﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using KSAWPFExtensions;
using KSASupport;
using KSASupport.BlobTracking;
using PhotoLoader;
using System.IO;
using System.Windows.Ink;

namespace KSAWPFDemo.InkCanvas
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class HandwritingSearch : UserControl
    {
        public HandwritingSearch()
        {
            InitializeComponent();
            this.Loaded += HandwritingSearch_Loaded;
        }

        void HandwritingSearch_Loaded(object sender, RoutedEventArgs e)
        {
            inkCanvas.StrokeCollected += inkCanvas_StrokeCollected;
        }

        void inkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            InkAnalyzer ia = new InkAnalyzer();
            ia.AddStroke(e.Stroke);
            AnalysisStatus status = ia.Analyze();
            if (status.Successful)
            {
               string recog =  ia.GetRecognizedString();
                MessageBox.Show("recognized: " + recog);

            }
           
        }

        private void inkCanvas_TouchDown(object sender, TouchEventArgs e)
        {
            //MessageBox.Show("touch");
        }

    }


    // Color generator: assigns a color to the new stroke.
    public class TouchColor
    {
        private int _count = 0;  // Rotating secondary color index

        // Returns color for the newly started stroke.
        public Color GetColor()
        {
            // Take current secondary color.
            Color color = _secondaryColors[_count];

            // Move to the next color in the array.
            _count = (_count + 1) % _secondaryColors.Length;

            return color;
        }

        static private Color[] _secondaryColors =    // Secondary colors
            {
                Colors.Black,
                Colors.Red,
                Colors.LawnGreen,
                Colors.Blue,
                Colors.Cyan,
                Colors.Magenta,
                Colors.Yellow
            };
    }
}
